import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Alert } from "../../../../com/mui/controls/Alert";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BaseItem } from "../common/BaseItem";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../common/ObjCreate";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../com/mui/controls/GButton";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ModelType } from "../../scene/modle/data/ModelType";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { TBargainShop } from "../../../../Message/Db/Tables/TBargainShop";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { ECategory } from "../../../../Message/Public/ECategory";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { BuyAlert } from "../pet/BuyAlert";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { LineBox } from "../guide/LineBox";
import { ColorInfo } from "../../resource/info/ColorInfo";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class DiscountShopCellRenderer
    
    export  class DiscountShopCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._pIngot = new Object /* flash.display.Bitmap */();
            this.createChildren();
            return;
        }

        protected onBuyBtnClickhandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._numericStepper.value;
            var loc2=Cache.instance.discountShop.isItemCostLimit(this.info.code, this.info.upperBuyAmount, loc1);
            var loc3=loc1 * this.info.lowerPrice;
            var loc4=Cache.instance.discountShop.isCostLimt(loc3);
            if (loc2) 
            {
                MsgManager.showRollTipsMsg(Language.getString(53028));
            }
            else if (loc4) 
            {
                Alert.show(Language.getString(90508), null, Alert.OK);
            }
            else if (loc1 > 0) 
            {
                this.toBuyHandler();
            }
            else if (loc1 == 0) 
            {
                if (loc4 = Cache.instance.discountShop.isCostLimt(this.info.lowerPrice)) 
                {
                    Alert.show(Language.getString(90508), null, Alert.OK);
                }
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            this._lightBg = new Object /* flash.display.Bitmap */();
            this._lightBg.y = 40;
            this._lightBg.x = 0;
            this.addChild(this._lightBg);
            this._itemCtn = new Object /* flash.display.Sprite */();
            this.addChild(this._itemCtn);
            this._itemCtn.x = 35;
            this._itemCtn.y = 22;
            this._bg = GlobalClass.getBitmap("PropBg");
            this._bg.x = 0;
            this._bg.y = 0;
            this._bg.width = 51;
            this._bg.height = 52.5;
            this._itemCtn.addChild(this._bg);
            this._propItem = new BaseItem();
            this._propItem.isDragAble = false;
            this._propItem.label = "";
            this._propItem.move(this._bg.x + 5, 4);
            this._itemCtn.addChild(this._propItem);
            this._propItem.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._propItem.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._nameLabel = new GLabel();
            this._nameLabel.x = this._textPox;
            this._nameLabel.y = 2;
            this._nameLabel.width = 120;
            this._nameLabel.height = 30;
            this.addChild(this._nameLabel);
            this._oPriceLabel = new GLabel();
            this._oPriceLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._oPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53013), "#B0EFFF");
            this._oPriceLabel.x = this._textPox;
            this._oPriceLabel.y = 18;
            this.addChild(this._oPriceLabel);
            this._oPriceNumLabel = new GLabel();
            this._oPriceNumLabel.width = 40;
            this._oPriceNumLabel.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._oPriceNumLabel.x = 130;
            this._oPriceNumLabel.y = 18;
            this.addChild(this._oPriceNumLabel);
            this._limitNumTxt = ObjCreate.createGTextField("", this._oPriceLabel.x, 55, 65, 20, this);
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._oIngot.x = 170;
            this._oIngot.y = 40;
            this.addChild(this._oIngot);
            this._pIngot = new Object /* flash.display.Bitmap */();
            this._pIngot.x = 170;
            this._pIngot.y = 60;
            this.addChild(this._pIngot);
            this._redLine = new Object /* flash.display.Shape */();
            this.addChild(this._redLine);
            this._pPriceLabel = new GLabel();
            this._pPriceLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
            this._pPriceLabel.x = this._textPox;
            this._pPriceLabel.y = 35;
            this.addChild(this._pPriceLabel);
            this._pPriceNumLabel = new GLabel();
            this._pPriceNumLabel.width = 35;
            this._pPriceNumLabel.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._pPriceNumLabel.x = 150;
            this._pPriceNumLabel.y = 35;
            this.addChild(this._pPriceNumLabel);
            this._numericStepper = new GNumericStepper();
            this._numericStepper.setSize(60, 22);
            this._numericStepper.move(this._textPox, 75);
            this._numericStepper.styleName = "NumericStepper";
            this._numericStepper.addEventListener(flash.events.Event.CHANGE, this.onBuyNumChange);
            this._numericStepper.drawNow();
            this._numericStepper.textField.setStyle("upSkin", GlobalClass.getScaleBitmap("WindowCenterB", new Object /* flash.geom.Rectangle */(4, 4, 36, 21)));
            this._numericStepper.textField.drawNow();
            this._numericStepper.maximum = 99;
            this._numericStepper.minimum = 0;
            this.addChild(this._numericStepper);
            this._buyBtn = new GButton();
            this._buyBtn.label = Language.getString(53021);
            this._buyBtn.styleName = "Button";
            this._buyBtn.setSize(50, 24);
            this._buyBtn.move(175, 73);
            this._buyBtn.drawNow();
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickhandler);
            this.addChild(this._buyBtn);
            this.lightEffSwf = new SWFPlayer();
            this.addChild(this.lightEffSwf);
            this.lightEffSwf.load("discountShopItemLight.swf", ModelType.Item, null);
            this.lightEffSwf.x = 50;
            this.lightEffSwf.y = 35;
            this.lightEffSwf.move(65, 35);
            this.lightEffSwf.stop();
            this.lightEffSwf.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.discountShop, this.onLoadHandler);
            return;
        }

        protected onOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isLoaded) 
            {
                this._lightBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.discountShop_showBg);
            }
            this.lightEffSwf.stop();
            this.lightEffSwf.visible = false;
            return;
        }

        protected onOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isLoaded) 
            {
                this._lightBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.discountShop_showBg_light);
            }
            this.lightEffSwf.play();
            this.lightEffSwf.visible = true;
            return;
        }

        /* internal  */get info(): TBargainShop
        {
            return this._data.info as TBargainShop;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc2=null;
            if (_data == arg1) 
            {
                return;
            }
            super.data = arg1;
            var loc1=Cache.instance.discountShop.getCurBuyMaxNum(this.info.code, this.info.upperBuyAmount, this.info.lowerPrice);
            this._numericStepper.maximum = loc1;
            this._numericStepper.value = 1;
            this._offer = this.info.lowerPrice;
            this._price = this.info.price;
            loc2 = new ItemData(this.info.code);
            this.category = loc2.category;
            this.type = loc2.type;
            this.colorInfo = ColorConfig.instance.getItemColor(loc2.color);
            if (this.colorInfo) 
            {
                this.colorName = this.colorInfo.color;
            }
            if (loc2.category != ECategory._ECategoryMount) 
            {
                this._propItem.toolTipType = ItemData.ToolTipType_Pack;
            }
            else 
            {
                this._propItem.toolTipType = ItemData.ToolTipType_Mounts;
            }
            this._propItem.itemData = loc2;
            this._propItem.drawNow();
            this._propItem.amount = -1;
            this._propItem.setSize(45, 45);
            this._nameLabel.htmlText = HTMLUtil.addColor(loc2.name, this.colorName);
            this._priceType = 2;
            this._priceImgName = GameDefConfig.instance.getEPrictUnitImg(this._priceType);
            if (this._priceImgName != "") 
            {
                this._oIngot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                this._pIngot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
            }
            if (!this.contains(this._oPriceLabel)) 
            {
                this._oPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53013), "#B0EFFF");
                this._oPriceLabel.x = this._textPox;
                this._oPriceLabel.y = 18;
                this.addChild(this._oPriceLabel);
            }
            this._pPriceLabel.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
            this._pPriceLabel.x = this._textPox;
            this._pPriceLabel.y = 35;
            this._oPriceNumLabel.htmlText = HTMLUtil.addColor(this._price.toString(), "#B0EFFF");
            this._pPriceNumLabel.htmlText = HTMLUtil.addColor(this._offer.toString(), "#F4FF01");
            this._pPriceNumLabel.x = 135;
            this._pPriceNumLabel.y = 35;
            var loc3=Cache.instance.discountShop.getLeftBuyNumByCode(this.info.code, this.info.upperBuyAmount);
            this._limitNumTxt.text = Language.getString(53015) + loc3.toString();
            this._pIngot.x = 170;
            this._pIngot.y = 20;
            var loc4=this._oPriceNumLabel.y;
            var loc5=this._oPriceNumLabel.x + this._oPriceNumLabel.width;
            var loc6=this._oPriceNumLabel.x + (40 - this._oPriceNumLabel.textField.width);
            this._redLine.graphics.clear();
            this._redLine.graphics.lineStyle(2, 16711680, 0.75);
            this._redLine.graphics.moveTo(loc6, loc4);
            this._redLine.graphics.lineTo(loc5, this._oPriceNumLabel.y + this._oPriceNumLabel.textField.height);
            return;
        }

        /* internal  */onLoadHandler(): void
        {
            this._isLoaded = true;
            this._lightBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.discountShop_showBg);
            return;
        }

        /* internal  */onBuyNumChange(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._numericStepper.value;
            return;
        }

        /* internal  */toBuyHandler(): void
        {
            var loc5=null;
            var loc6=null;
            var loc1=this._numericStepper.value;
            var loc2=loc1 * this.info.lowerPrice;
            var loc3="DiscountBuyAlert";
            var loc4=!PulseSharedObject.isTodayNotTips(loc3);
            if (BuyAlert.checkMoney(EPrictUnit._EPriceUnitGold, loc2)) 
            {
                loc5 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitGold);
                loc6 = Language.getStringByParam(54172, loc1, ItemsUtil.getItemName(new ItemData(this.info.code)), loc2, loc5);
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.DiscountShopBuy, this.BuyAlertCB, loc6, null, Alert.OK | Alert.CANCEL, null, null, null, 4, loc1);
            }
            return;
        }

        /* internal  */BuyAlertCB(arg1: Array<any>): void
        {
            var loc1=arg1[0];
            Dispatcher.dispatchEvent(new DataEvent(EventName.BuyDiscountShopItem, {"id": this.info.code, "amount": loc1}));
            return;
        }

        protected /* override */ draw(): void
        {
            super.draw();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            return;
        }

        protected /* var */_numericStepper: GNumericStepper;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceImgName: string;

        /* internal */ /* var */_redLine: Object /* flash.display.Shape */;

        /* internal */ /* var */_lineBox: LineBox;

        /* internal */ /* var */colorInfo: ColorInfo;

        /* internal */ /* var */colorName: string;

        /* internal */ /* var */label: int;

        /* internal */ /* var */_pPriceLabel: GLabel;

        /* internal */ /* var */type: int;

        /* internal */ /* var */_price: int;

        /* internal */ /* var */_offer: int;

        /* internal */ /* var */_isLoaded: Boolean;

        /* internal */ /* var */_lightBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */lightEffSwf: SWFPlayer;

        /* internal */ /* var */_textPox: number=110;

        /* internal */ /* var */_itemCtn: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_oPriceLabel: GLabel;

        /* internal */ /* var */_limitNumTxt: GTextFiled;

        /* internal */ /* var */_oPriceNumLabel: GLabel;

        /* internal */ /* var */_pPriceNumLabel: GLabel;

        /* internal */ /* var */category: int;

        /* internal */ /* var */_oIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_pIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buyBtn: GButton;

        public static /* var */isWider: Boolean=false;

        /* internal */ /* var */_labelBitmap: Object /* flash.display.Bitmap */;
    }

            DiscountShopCellRenderer.isWider = false;
        